<?
class FuzzyValue {

    private $v0;
    private $v1;
    private $v2;
    private $v3;

    public function __construct($v0,$v1,$v2,$v3){
        $this->v0 = $v0;
        $this->v1 = $v1;
        $this->v2 = $v2;
        $this->v3 = $v3;
    }


    public function add($f2){


        $v0 = $this->v0 + $f2->v0;
        $v1 = $this->v1 + $f2->v1;
        $v2 = $this->v2 + $f2->v2;
        $v3 = $this->v3 + $f2->v3;

        return  new FuzzyValue($v0,$v1,$v2,$v3);

    }

    public function mul($f2){
        $v0 = $this->v0 * $f2->v0;
        $v1 = $this->v1 * $f2->v1;
        $v2 = $this->v2 * $f2->v2;
        $v3 = $this->v3 * $f2->v3;

        return new FuzzyValue($v0,$v1,$v2,$v3);
    }

    public function div($f2){
        $v0 = $this->v0 / $f2->v0;
        $v1 = $this->v1 / $f2->v1;
        $v2 = $this->v2 / $f2->v2;
        $v3 = $this->v3 / $f2->v3;

        return new FuzzyValue($v0,$v1,$v2,$v3);
    }

    public function avg(){
        return (($this->v0 + $this->v1 + $this->v2 + $this->v3)/4); 
    }


    public function __toString()
    {
        return sprintf("(%.1f,%.1f,%.1f,%.1f)", $this->v0, $this->v1, $this->v2, $this->v3);
        //return sprintf("(%d,%d,%d,%d)", $this->v0, $this->v1, $this->v2, $this->v3);
    }


    static public function fromBoolean($value){
        switch($value){
            case "si":
                return new FuzzyValue(10,10,10,10);
            case "no":
                return new FuzzyValue(0,0,0,0);
            default:
                throw new Exception("Unknown value '" . $value . "'for boolean type");
        }
       

 
    }

    static public function fromLinguistic($value){
        switch($value){
            case "nada":
                return new FuzzyValue(0.0,0.0,1.2,2.2);
            case "poco":
                return new FuzzyValue(1.2,2.2,3.4,4.4);
            case "regular":
                return new FuzzyValue(3.4,4.4,5.6,6.6);
            case "mucho":
                return new FuzzyValue(5.6,6.6,7.8,8.8);
            case "todo":
                return new FuzzyValue(7.8,8.8,10.0,10.0);
            default:
                throw new Exception("Unknown value'" . $value . "' for Linguistic type");
        }
    }


    static public function fromNumeric($value){
        return new FuzzyValue($value, $value, $value, $value);
    }



}


?>
